package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.Map;
import com.ruoyi.system.service.IMapService;
import com.ruoyi.system.utils.MapLoad;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 地图管理Controller
 * 
 * @author zqh
 * @date 2022-06-29
 */
@RestController
@RequestMapping("/system/map")
public class MapController extends BaseController
{
    @Autowired
    private IMapService mapService;

    /**
     * 查询地图管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:map:list')")
    @GetMapping("/list")
    public TableDataInfo list(Map map)
    {
        startPage();
        List<Map> list = mapService.selectMapList(map);
        return getDataTable(list);
    }

    /**
     * 导出地图管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:map:export')")
    @Log(title = "地图管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Map map)
    {
        List<Map> list = mapService.selectMapList(map);
        ExcelUtil<Map> util = new ExcelUtil<Map>(Map.class);
        util.exportExcel(response, list, "地图管理数据");
    }

    /**
     * 获取地图管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:map:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(mapService.selectMapById(id));
    }

    /**
     * 新增地图管理
     */
    @PreAuthorize("@ss.hasPermi('system:map:add')")
    @Log(title = "地图管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Map map)
    {
        MapLoad mapLoad = new MapLoad();
        mapLoad.LoadMap(map.getLatUp(),map.getLonUp(),map.getLatDown(),map.getLonDown(),map.getName());
        return toAjax(mapService.insertMap(map));
    }

    /**
     * 修改地图管理
     */
    @PreAuthorize("@ss.hasPermi('system:map:edit')")
    @Log(title = "地图管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Map map)
    {
        return toAjax(mapService.updateMap(map));
    }

    /**
     * 删除地图管理
     */
    @PreAuthorize("@ss.hasPermi('system:map:remove')")
    @Log(title = "地图管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(mapService.deleteMapByIds(ids));
    }

}
